//
//  UIImageView+Extension.swift
//  Library_y
//
//  Created by JC on 2023/6/6.
//

import Foundation
import UIKit

extension UIImageView {
    
    // 360度旋转图片
    public func rotate360Degree() {
        // 让其在z轴旋转
        let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
        // 旋转角度
        rotationAnimation.toValue = NSNumber(value: Double.pi * 2.0)
        // 旋转周期
        rotationAnimation.duration = 2
        // 旋转累加角度
        rotationAnimation.isCumulative = true
        // 旋转次数
        rotationAnimation.repeatCount = 100000
        layer.add(rotationAnimation, forKey: "rotationAnimation")
    }
    
    // 停止旋转
    public func stopRotate() {
        layer.removeAllAnimations()
    }
}

